<?php include("../public/views/function.php");?>
<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no" />
    <title>拾光 • 图书馆</title>
    <meta name="apple-mobile-web-app-capable" content="yes" />
    <meta name="apple-mobile-web-app-status-bar-style" content="black" />
    <meta name="format-detection"content="telephone=no, email=no" />
    <meta name="renderer" content="webkit">

    <meta name="title" content="拾光 • 图书馆" />
    <meta name="description" content="燕大人自己的图书管理小帮手~提醒你按时还书、及时续借~" />
    <meta name="img" content="http://source.timepicker.cn/uploads/default/library.png-120" />
    <!--icon-->
    <link rel="shortcut icon" href="http://source.timepicker.cn/uploads/default/library.png-120" />
    <!--拾光css-->
    <link rel="stylesheet" href="http://source.timepicker.cn/ptime_v0.3.min.css">
    <link rel="stylesheet" href="/css/app.css">

    <!--头部-->
    <header class="bg-mcolor fixed top" style="background:#918ff0 !important;" id="topbar">
        <a href="/" style="color:#fff;"><h1>拾光 • 图书馆</h1></a>
    </header>
</head>

<body class="agent-<?=$user_agent?>" id="top">
    <div style="overflow:hidden;line-height: 24px;font-size: 12px;border:0;box-shadow:none;background:#ede7f6;padding:10px;" class="section top" onclick="librarylogin()">
        <span class="left" style="color: #333;">最近同步时间：
            <span style="font-size:14px;"><?php if($info_arr['sync_time']=='0000-00-00 00:00:00'){ echo '<span style="color:red;">从未同步</span>'; }else{ echo $info_arr['sync_time']; } ?>
            </span>
        <span class="fcolor right" >点击同步</span>
    </div>
    <!--其他区域-->
    <section>
        <div style="overflow:hidden;padding:0 20px;margin:20px 0;">
            <a href="/blike" class="circle-div">
                <img class="circle-button" src="img/imgsc.png"/>
                <p>收藏</p>
            </a>
            <a href="/bnow" class="circle-div">
                <img class="circle-button" src="img/imgdq.png"/>
                <p>当前借阅</p>
            </a>
            <a href="/bhistory" class="circle-div">
                <img class="circle-button mcolor" src="img/imgls.png"/>
                <p>历史借阅</p>
            </a>
        </div>
        <hr style="margin:0;">
        <div class="item block">
            <p style="font-size:14px;color:#333"><strong>到期信息</strong></p>
            <p style="overflow:hidden;">
                <span>五天内即将到期的书：<a href="/bnow"><strong class="mcolor" style="font-size:16px;"><?php if($is_imported == 0){echo '不造多少';}else{echo $info_arr['five'];} ?></strong></a>本</span>
            </p>
        </div>
        <div class="item block">
            <img src="img/wel.png" class="left" style="height:100px;">
            <a href="/bhistory" class="left" style="word-wrap:break-word;word-break:break-all;color:#909090">
                <p>少年,</p>
                你累计借书<span class="mcolor" style="font-size:16px;margin:0 4px;"><?php if($is_imported == 0){echo '不造多少';}else{echo $info_arr['count'];} ?></span>本，读书排名超过<span class="mcolor" style="font-size:16px;margin:0 4px;"><?php if($is_imported == 0){echo '不造多少';}else{echo $info_arr['over_num'];} ?></span>的人啦~~
                <p>

                    <?php if($is_imported == 0){echo '不造获得什么称号';}else{echo '已获得<span class="mcolor" style="font-size:16px;margin:0 4px;">'.$info_arr['level'].'称号';} ?></span>。
                </p>
            </a>
        </div>
    </section>
<div class="shadow" id="iframeBox" onclick="toggle('iframeBox')" style="display: none;background: rgba(0,0,0,.4);position: fixed;top: 0;left: 0;width: 100%;height: 100%;color: #fff;z-index: 2;" >
    <iframe id="iframe" name="iframe" src="">  
    </iframe>
</div>

<?php  $domain = 'timepicker.cn';?>
<?php  $campus_url = 'http://ptime.timepicker.cn';?>

<?php include 'footer.php';?>

<script type="text/javascript">
    var is_iframe;
    document.domain = '<?=$domain?>';


    var temp_agent = '<?php if(isset($user_agent)){ echo $user_agent; }else{ echo 0; } ?>';
    var time = '<?php if(isset($info_arr)){ echo $info_arr['sync_time']; }else{ echo 0; } ?>';
    if (temp_agent=='ptimeandroid'||temp_agent=='wechat'||temp_agent=='mqq'||temp_agent=='ptimeios') {
        $("section").css("padding-top","44px");
    };
//获取用户名
    var number = '<?php if(isset($number)){ echo $number; }else{ echo 0; } ?>';
    $("#gotop").hide();//置顶隐藏;
    // $("body").css("padding-top","0 !important");
    $(document).ready(function() {
        $("#user-center").html('<img style="height:60px;border-radius:30px;" src="img/imgleft.png"/>');//图标变化
    })

    $("#user-center").css("left","20px !important");
    $("#user-center").show();

//获取图书馆登录验证码
    function getcode(){
        $.ajax({
            type:"get",
            url:"api/lib/pre",
            dataType:"json",//text/xml/json，非必须
            success:function(data){//回调函数，非必须
                if (!data.error) {
                    $("#vcodeimg").attr("src",data.pic);
                }else{
                    toast(data.message);
                };
            }
        });
    }

    
//图书馆登录
    function librarylogin(){
            $("#loading").show();
            $.ajax({
                type:"get",
                url:"/api/sync",
                dataType:"json",//text/xml/json，非必须
                success:function(data){//回调函数，非必须
                    $("#loading").hide();
                    // toast(JSON.stringify(data));
                    if (!data.error) {
                        toast("同步成功！");
                    }else{
                        if (data.result=='tokenNull') {
                            is_iframe = true;
                            $("#iframe").attr("src","http://ptime.timepicker.cn/campus/oauth2/auth?state=1&user_id="+<?php echo $user_id;?>+"&system_cat=library");
                            $("#iframeBox").show();
                        }else{
                            toast(data.message);
                        };
                        
                    };   
                }
            });
        
        // if (time=='0000-00-00 00:00:00') {
        //     getcode();
        //     var temp = '<input id="username" class="binput" disabled="disabled" type="text" value="'+number+'"/><input id="password" class="binput" type="password" placeholder="图书馆密码，默认888"/>';
        //     SetDialogEvent(temp,login);
        // }else{
        //     $("#loading").show();
        //     $.ajax({
        //         type:"get",
        //         url:"/api/lib/extra",
        //         dataType:"json",//text/xml/json，非必须
        //         success:function(data){//回调函数，非必须
        //             $("#loading").hide();
        //             if (!data.error) {
        //                 window.location.href="/"+;
        //             }else{
        //                 getcode();

        //                 var temp = '<input id="username" class="binput" disabled="disabled" type="text" value="'+number+'"/><input id="password" class="binput" type="password" placeholder="图书馆密码，默认888"/>';
        //                 SetDialogEvent(temp,login);
        //             };
        //         }
        //     });
        // };

    }
    function iframeCallback(){librarylogin();};
</script>
